﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SolutionModel;
using SolutionBLL;
using SFast;


public partial class admin_newsSystem_CommonClass_index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    #region Api: 获取分类 返回json
    /// <summary>
    /// 获取分类
    /// </summary>
    /// <returns></returns>
    public String GetClass()
    {
        CommonClassType where = (CommonClassType)1;
        if (Request["type"]!= null)
        {
            where = (CommonClassType)Enum.Parse(typeof(CommonClassType), Request["type"]);
        }
        String cid = String.Empty;
        if (!String.IsNullOrEmpty(Request["cid"]))
        {
            cid = Request["cid"];
        }

        CommonClassBLL bll = new CommonClassBLL();
        List<TreeGridModel> list = bll.GetListByType(where, cid);

        //是否添加根目录
        if (Request["root"] != null)
        {
            list = new List<TreeGridModel>(){
                new TreeGridModel(){
                    ID = 0,
                    PID = 0,
                    Name = where._GetRemark(),
                    CCType = where.ToString(),
                    children =list
                }
            };
        }
        String JsonStr = list == null ? "" : list._ToJsonStr();
        //Response.Write(JsonStr);
        return JsonStr;
    }
    #endregion

    #region Api:解析枚举 生成Json格式字符串
    /// <summary>
    /// 解析枚举 生成Json格式字符串
    /// </summary>
    /// <returns></returns>
    public String GetClassType()
    {
        List<object> list = new List<object>();
        Array Val = Enum.GetValues(typeof(CommonClassType));
        foreach (CommonClassType item in Val)
        {
            list.Add(new
                {
                    ID = item.ToString(),
                    Name = item._GetRemark()
                });
        }
        return list._ToJsonStr();
    }
    #endregion

}
